#!/usr/bin/env bash
#编译+部署项目站点

#1.配置环境变量
#export PROJ_PATH=/root/web/git_projects在Jenkins中,是  ~ .jenkins/ 目录
#export TOMCAT_PATH=/root/web/apache-tomcat-8.0.52

#base函数
killTomcat(){
	pid=`ps -ef|grep tomcat|grep java|awk '{print $2}'`
	echo "Tomcat id list :$pid"
	if [ "$pid" = "" ]
	then 
		echo "no tomcat run in this machine"
	else
		kill -9 $pid
	fi
}
cd $PROJ_PATH/spring_boot/web-manager

#3.maven打包项目
mvn clean install
#4.杀掉tomcat进程
killTomcat
#5.删除原有工程
rm -rf $TOMCAT_PATH/webapps/web-manager-mvc-1.0-SNAPSHOT.jar
rm -rf $TOMCAT_PATH/webapps/spring_bootjar
#6.复制新的工程到Tomcat目录下
cp $PROJ_PATH/spring_boot/web-manager/web-manager-mvc/target/web-manager-mvc-1.0-SNAPSHOT.jar $TOMCAT_PATH/webapps/
#7.启动Tomcat
cd $TOMCAT_PATH/
sh bin/startup.sh
#8.输出控制台日志
tail -f logs/catalina.out

BUILD_ID=DONOTKILLME
export PROJ_PATH=/root/web/git_projects
sh $PROJ_PTAH/spring_boot/deploy.sh